package dao;

import dao.inte.OrderRepository;
import domain.shop.BasketItem;
import domain.shop.Order;

import javax.inject.Singleton;
import javax.persistence.Query;
import java.util.List;

@Singleton
public class OrderRepositoryImpl extends AbstractEntityRepository<Order> implements OrderRepository {
    public OrderRepositoryImpl() {
        super(Order.class);
    }

    @Override
    protected Class<Order> getEntityClass() {
        return Order.class;
    }

    /**
     * This method return from database list of all basket items from active order of specific user
     *
     * @param id - id of user
     * @return list of all basket items from active order of specific user with enter ID
     */
    @Deprecated

    public List<BasketItem> findAllBasketItemsOfActiveOrderByID(long id) {
        Query q = entityManager.createQuery("from Order o where o.user.id = :id AND o.active = true");
        q.setParameter("id", id);
        return ((Order) q.getSingleResult()).getProducts();

    }


}
